-- example HTTP POST script which demonstrates setting the
-- HTTP method, body, and adding a header


-- 初始化
function init(args)
    local msg = "thread addr: %s"
--    print(msg:format(wrk.thread.addr))
    print()
end

-- 请求
-- function request()
--     -- print("----requeset 请求")

--     requests = requests + 1
--     return wrk.requeset()
-- end
function request()
--    requests = requests + 1
   return wrk.request()
end

function response(status, headers, body)
    print(status)
    PrintTable(headers)
    -- print(body)
end


---
-- @function: 打印table的内容，递归
-- @param: tbl 要打印的table
-- @param: level 递归的层数，默认不用传值进来
-- @param: filteDefault 是否过滤打印构造函数，默认为是
-- @return: return
function PrintTable( tbl , level, filteDefault)
  local msg = ""
  filteDefault = filteDefault or true --默认过滤关键字（DeleteMe, _class_type）
  level = level or 1
  local indent_str = ""
  for i = 1, level do
    indent_str = indent_str.."  "
  end

  print(indent_str .. "{")
  for k,v in pairs(tbl) do
    if filteDefault then
      if k ~= "_class_type" and k ~= "DeleteMe" then
        local item_str = string.format("%s%s = %s", indent_str .. " ",tostring(k), tostring(v))
        print(item_str)
        if type(v) == "table" then
          PrintTable(v, level + 1)
        end
      end
    else
      local item_str = string.format("%s%s = %s", indent_str .. " ",tostring(k), tostring(v))
      print(item_str)
      if type(v) == "table" then
        PrintTable(v, level + 1)
      end
    end
  end
  print(indent_str .. "}")
end

-- 测试printTable函数
-- local x = {a = 20,20,60,{a = {a = 1,2323},2323}}
-- PrintTable(x)
